home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as / sprite / RCS / write.c,v < prev   
Encoding:
Text File  |  1991-08-27  |  36.3 KB  |  1,245 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     91.08.26.23.33.15;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     91.08.26.23.08.31;  author rab;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Hacked the magic number stuff.  The new a.out.h uses bitfields which are
  27. not compatible with how write.c works.  Hence the hack.
  28. @
  29. text
  30. @/* write.c - emit .o file - Copyright(C)1986 Free Software Foundation, Inc.
  31.    Copyright (C) 1986,1987 Free Software Foundation, Inc.
  32.  
  33. This file is part of GAS, the GNU Assembler.
  34.  
  35. GAS is free software; you can redistribute it and/or modify
  36. it under the terms of the GNU General Public License as published by
  37. the Free Software Foundation; either version 1, or (at your option)
  38. any later version.
  39.  
  40. GAS is distributed in the hope that it will be useful,
  41. but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43. GNU General Public License for more details.
  44.  
  45. You should have received a copy of the GNU General Public License
  46. along with GAS; see the file COPYING.  If not, write to
  47. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  48.  
  49. /* 
  50.  
  51.    Umm, with real good luck, this thing should be set up to do byteordering
  52.    correctly, but I may have managed to miss a place or two.  Treat a.out
  53.    very carefully until you're SURE that it works. . .
  54.  
  55.    In order to cross-assemble the target machine must have an a.out header
  56.    similar to the one in a.out.h on THIS machine.  Byteorder doesn't matter;
  57.    we take special care of it, but the numbers must be the same SIZE (# of
  58.    bytes) and in the same PLACE.  If this is not true, you will have some
  59.    trouble.
  60.  */
  61.  
  62. #include "as.h"
  63. #include "md.h"
  64. #include "subsegs.h"
  65. #include "obstack.h"
  66. #include "struc-symbol.h"
  67. #include "write.h"
  68. #include "symbols.h"
  69.  
  70. #ifdef SPARC
  71. #include "sparc.h"
  72. #endif
  73.  
  74. void    append();
  75.  
  76. #ifdef hpux
  77. #define EXEC_MACHINE_TYPE HP9000S200_ID
  78. #endif
  79.  
  80. /*
  81.  * In: length of relocation (or of address) in chars: 1, 2 or 4.
  82.  * Out: GNU LD relocation length code: 0, 1, or 2.
  83.  */
  84.  
  85. static unsigned char
  86.  
  87. nbytes_r_length [] = {
  88.   42, 0, 1, 42, 2
  89.   };
  90.  
  91.  
  92. static struct frag *    text_frag_root;
  93. static struct frag *    data_frag_root;
  94.  
  95. static struct frag *    text_last_frag;    /* Last frag in segment. */
  96. static struct frag *    data_last_frag;    /* Last frag in segment. */
  97.  
  98. static struct exec    the_exec;
  99.  
  100. static long int string_byte_count;
  101.  
  102. static char *        the_object_file;
  103.  
  104. #ifndef SPARC
  105. static
  106. #endif
  107. char *        next_object_file_charP;    /* Tracks object file bytes. */
  108.  
  109. static long int        size_of_the_object_file; /* # bytes in object file. */
  110.  
  111. /* static long int        length; JF unused */    /* String length, including trailing '\0'. */
  112.  
  113. static void    relax_segment();
  114. void        emit_segment();
  115. static relax_addressT    relax_align();
  116. static long int    fixup_segment();
  117. #ifndef SPARC
  118. static void        emit_relocations();
  119. #endif
  120. /*
  121.  *            fix_new()
  122.  *
  123.  * Create a fixS in obstack 'notes'.
  124.  */
  125. void
  126. #ifdef SPARC
  127. fix_new (frag, where, size, add_symbol, sub_symbol, offset, pcrel, r_type)
  128. #else
  129. fix_new (frag, where, size, add_symbol, sub_symbol, offset, pcrel)
  130. #endif
  131.      fragS *    frag;        /* Which frag? */
  132.      int    where;        /* Where in that frag? */
  133.      short int    size;        /* 1, 2  or 4 usually. */
  134.      symbolS *    add_symbol;    /* X_add_symbol. */
  135.      symbolS *    sub_symbol;    /* X_subtract_symbol. */
  136.      long int    offset;        /* X_add_number. */
  137.      int    pcrel;        /* TRUE if PC-relative relocation. */
  138. #ifdef SPARC
  139.     int        r_type;
  140. #endif
  141. {
  142.   register fixS *    fixP;
  143.  
  144.   fixP = (fixS *)obstack_alloc(¬es,sizeof(fixS));
  145.  
  146.   fixP -> fx_frag    = frag;
  147.   fixP -> fx_where    = where;
  148.   fixP -> fx_size    = size;
  149.   fixP -> fx_addsy    = add_symbol;
  150.   fixP -> fx_subsy    = sub_symbol;
  151.   fixP -> fx_offset    = offset;
  152.   fixP -> fx_pcrel    = pcrel;
  153.   fixP -> fx_next    = * seg_fix_rootP;
  154.  
  155.   /* JF these 'cuz of the NS32K stuff */
  156.   fixP -> fx_im_disp    = 0;
  157.   fixP -> fx_pcrel_adjust = 0;
  158.   fixP -> fx_bsr    = 0;
  159.   fixP ->fx_bit_fixP    = 0;
  160.  
  161. #ifdef SPARC
  162.   fixP->fx_r_type = r_type;
  163. #endif
  164.  
  165.   * seg_fix_rootP = fixP;
  166. }
  167.  
  168. void
  169. write_object_file()
  170. {
  171.   register struct frchain *    frchainP; /* Track along all frchains. */
  172.   register fragS *        fragP;    /* Track along all frags. */
  173.   register struct frchain *    next_frchainP;
  174.   register fragS * *        prev_fragPP;
  175.   register char *        name;
  176.   register symbolS *        symbolP;
  177.   register symbolS **        symbolPP;
  178.   /* register fixS *        fixP; JF unused */
  179.   unsigned
  180.       text_siz,
  181.     data_siz,
  182.     syms_siz,
  183.     tr_siz,
  184.     dr_siz;
  185.   void output_file_create();
  186.   void output_file_append();
  187.   void output_file_close();
  188.   void gdb_emit();
  189.   void gdb_end();
  190.   extern long omagic;        /* JF magic # to write out.  Is different for
  191.                    Suns and Vaxen and other boxes */
  192.  
  193. #ifdef    VMS
  194.   /*
  195.    *    Under VMS we try to be compatible with VAX-11 "C".  Thus, we
  196.    *    call a routine to check for the definition of the procedure
  197.    *    "_main", and if so -- fix it up so that it can be program
  198.    *    entry point.
  199.    */
  200.   VMS_Check_For_Main();
  201. #endif /* VMS */
  202.   /*
  203.    * After every sub-segment, we fake an ".align ...". This conforms to BSD4.2
  204.    * brane-damage. We then fake ".fill 0" because that is the kind of frag
  205.    * that requires least thought. ".align" frags like to have a following
  206.    * frag since that makes calculating their intended length trivial.
  207.    */
  208. #define SUB_SEGMENT_ALIGN (2)
  209.   for ( frchainP=frchain_root; frchainP; frchainP=frchainP->frch_next )
  210.     {
  211. #ifdef    VMS
  212.       /*
  213.        *    Under VAX/VMS, the linker (and PSECT specifications)
  214.        *    take care of correctly aligning the segments.
  215.        *    Doing the alignment here (on initialized data) can
  216.        *    mess up the calculation of global data PSECT sizes.
  217.        */
  218. #undef    SUB_SEGMENT_ALIGN
  219. #define    SUB_SEGMENT_ALIGN ((frchainP->frch_seg != SEG_DATA) ? 2 : 0)
  220. #endif    /* VMS */
  221.       subseg_new (frchainP -> frch_seg, frchainP -> frch_subseg);
  222.       frag_align (SUB_SEGMENT_ALIGN, 0);
  223.                 /* frag_align will have left a new frag. */
  224.                 /* Use this last frag for an empty ".fill". */
  225.       /*
  226.        * For this segment ...
  227.        * Create a last frag. Do not leave a "being filled in frag".
  228.        */
  229.       frag_wane (frag_now);
  230.       frag_now -> fr_fix    = 0;
  231.       know( frag_now -> fr_next == NULL );
  232.       /* know( frags . obstack_c_base == frags . obstack_c_next_free ); */
  233.       /* Above shows we haven't left a half-completed object on obstack. */
  234.     }
  235.  
  236.   /*
  237.    * From now on, we don't care about sub-segments.
  238.    * Build one frag chain for each segment. Linked thru fr_next.
  239.    * We know that there is at least 1 text frchain & at least 1 data frchain.
  240.    */
  241.   prev_fragPP = &text_frag_root;
  242.   for ( frchainP=frchain_root; frchainP; frchainP=next_frchainP )
  243.     {
  244.       know( frchainP -> frch_root );
  245.       * prev_fragPP = frchainP -> frch_root;
  246.       prev_fragPP = & frchainP -> frch_last -> fr_next;
  247.       if (   ((next_frchainP = frchainP->frch_next) == NULL)
  248.       || next_frchainP == data0_frchainP)
  249.     {
  250.       prev_fragPP = & data_frag_root;
  251.       if ( next_frchainP )
  252.         {
  253.           text_last_frag = frchainP -> frch_last;
  254.         }
  255.       else
  256.         {
  257.           data_last_frag = frchainP -> frch_last;
  258.         }
  259.     }
  260.     }                /* for(each struct frchain) */
  261.  
  262.   /*
  263.    * We have two segments. If user gave -R flag, then we must put the
  264.    * data frags into the text segment. Do this before relaxing so
  265.    * we know to take advantage of -R and make shorter addresses.
  266.    */
  267.   if ( flagseen [ 'R' ] )
  268.     {
  269.       fixS *tmp;
  270.  
  271.       text_last_frag -> fr_next = data_frag_root;
  272.       text_last_frag = data_last_frag;
  273.       data_last_frag = NULL;
  274.       data_frag_root = NULL;
  275.       if(text_fix_root) {
  276.     for(tmp=text_fix_root;tmp->fx_next;tmp=tmp->fx_next)
  277.       ;
  278.     tmp->fx_next=data_fix_root;
  279.       } else
  280.         text_fix_root=data_fix_root;
  281.       data_fix_root=NULL;
  282.     }
  283.  
  284.   relax_segment (text_frag_root, SEG_TEXT);
  285.   relax_segment (data_frag_root, SEG_DATA);
  286.   /*
  287.    * Now the addresses of frags are correct within the segment.
  288.    */
  289.  
  290.   know(   text_last_frag -> fr_type   == rs_fill && text_last_frag -> fr_offset == 0 );
  291.   text_siz=text_last_frag->fr_address;
  292. #ifdef SPARC
  293.   text_siz= (text_siz+7)&(~7);
  294.   text_last_frag->fr_address=text_siz;
  295. #endif
  296.   md_number_to_chars((char *)&the_exec.a_text,text_siz, sizeof(the_exec.a_text));
  297.   /* the_exec . a_text = text_last_frag -> fr_address; */
  298.  
  299.   /*
  300.    * Join the 2 segments into 1 huge segment.
  301.    * To do this, re-compute every rn_address in the SEG_DATA frags.
  302.    * Then join the data frags after the text frags.
  303.    *
  304.    * Determine a_data [length of data segment].
  305.    */
  306.   if (data_frag_root)
  307.     {
  308.       register relax_addressT    slide;
  309.  
  310.       know(   text_last_frag -> fr_type   == rs_fill && text_last_frag -> fr_offset == 0 );
  311.       data_siz=data_last_frag->fr_address;
  312. #ifdef SPARC
  313.       data_siz += (8 - (data_siz % 8)) % 8;
  314.       data_last_frag->fr_address = data_siz;
  315. #endif
  316.       md_number_to_chars((char *)&the_exec.a_data,data_siz,sizeof(the_exec.a_data));
  317.       /* the_exec . a_data = data_last_frag -> fr_address; */
  318.       slide = text_siz; /* Address in file of the data segment. */
  319.       for (fragP = data_frag_root;
  320.        fragP;
  321.        fragP = fragP -> fr_next)
  322.     {
  323.       fragP -> fr_address += slide;
  324.     }
  325.       know( text_last_frag );
  326.       text_last_frag -> fr_next = data_frag_root;
  327.     }
  328.   else {
  329.       md_number_to_chars((char *)&the_exec.a_data,0,sizeof(the_exec.a_data));
  330.       data_siz = 0;
  331.   }
  332.  
  333.   bss_address_frag . fr_address = text_siz + data_siz;
  334. #ifdef SPARC
  335.   local_bss_counter=(local_bss_counter+7)&(~7);
  336. #endif
  337.   md_number_to_chars((char *)&the_exec.a_bss,local_bss_counter,sizeof(the_exec.a_bss));
  338.  
  339.           
  340.   /*
  341.    *
  342.    * Crawl the symbol chain.
  343.    *
  344.    * For each symbol whose value depends on a frag, take the address of
  345.    * that frag and subsume it into the value of the symbol.
  346.    * After this, there is just one way to lookup a symbol value.
  347.    * Values are left in their final state for object file emission.
  348.    * We adjust the values of 'L' local symbols, even if we do
  349.    * not intend to emit them to the object file, because their values
  350.    * are needed for fix-ups.
  351.    *
  352.    * Unless we saw a -L flag, remove all symbols that begin with 'L'
  353.    * from the symbol chain.
  354.    *
  355.    * Count the (length of the nlists of the) (remaining) symbols.
  356.    * Assign a symbol number to each symbol.
  357.    * Count the number of string-table chars we will emit.
  358.    *
  359.    */
  360.   know( zero_address_frag . fr_address == 0 );
  361.   string_byte_count = sizeof( string_byte_count );
  362.  
  363.   /* JF deal with forward references first. . . */
  364.   for(symbolP=symbol_rootP;symbolP;symbolP=symbolP->sy_next) {
  365.       if(symbolP->sy_forward) {
  366.         symbolP->sy_value+=symbolP->sy_forward->sy_value+symbolP->sy_forward->sy_frag->fr_address;
  367.         symbolP->sy_forward=0;
  368.     }
  369.   }
  370.   symbolPP = & symbol_rootP;    /* -> last symbol chain link. */
  371.   {
  372.     register long int        symbol_number;
  373.  
  374.     symbol_number = 0;
  375.     while (symbolP  = * symbolPP)
  376.       {
  377.     name = symbolP -> sy_name;
  378.     if(flagseen['R'] && (symbolP->sy_nlist.n_type&N_DATA)) {
  379.       symbolP->sy_nlist.n_type&= ~N_DATA;
  380.       symbolP->sy_nlist.n_type|= N_TEXT;
  381.     }
  382.     /* if(symbolP->sy_forward) {
  383.       symbolP->sy_value += symbolP->sy_forward->sy_value + symbolP->sy_forward->sy_frag->fr_address;
  384.     } */
  385.     
  386.     symbolP -> sy_value += symbolP -> sy_frag -> fr_address;
  387.         /* JF the 128 bit is a hack so stabs like
  388.            "LET_STMT:23. . ."  don't go away */
  389.     /* CPH: 128 bit hack is moby loser.  N_SO for file "Lower.c"
  390.        fell through the cracks.  I think that N_STAB should be
  391.        used instead of 128. */
  392.         /* JF the \001 bit is to make sure that local labels
  393.            ( 1: - 9: don't make it into the symtable either */
  394. #ifndef    VMS    /* Under VMS we need to keep local symbols */
  395.     if ( !name || (symbolP->sy_nlist.n_type&N_STAB)
  396.         || (name[0]!='\001' && (flagseen ['L'] || name [0] != 'L' )))
  397. #endif    /* not VMS */
  398.       {
  399.         symbolP -> sy_number = symbol_number ++;
  400. #ifndef    VMS
  401.         if (name)
  402.           {            /* Ordinary case. */
  403.         symbolP -> sy_name_offset = string_byte_count;
  404.         string_byte_count += strlen (symbolP  -> sy_name) + 1;
  405.           }
  406.         else            /* .Stabd case. */
  407. #endif    /* not VMS */
  408.         symbolP -> sy_name_offset = 0;
  409.         symbolPP = & (symbolP -> sy_next);
  410.       }
  411. #ifndef    VMS
  412.     else
  413.         * symbolPP = symbolP -> sy_next;
  414. #endif    /* not VMS */
  415.       }                /* for each symbol */
  416.  
  417.     syms_siz = sizeof( struct nlist) * symbol_number;
  418.     md_number_to_chars((char *)&the_exec.a_syms,syms_siz,sizeof(the_exec.a_syms));
  419.     /* the_exec . a_syms = sizeof( struct nlist) * symbol_number; */
  420.   }
  421.  
  422.   /*
  423.    * Addresses of frags now reflect addresses we use in the object file.
  424.    * Symbol values are correct.
  425.    * Scan the frags, converting any ".org"s and ".align"s to ".fill"s.
  426.    * Also converting any machine-dependent frags using md_convert_frag();
  427.    */
  428.   subseg_change( SEG_TEXT, 0);
  429.  
  430.   for (fragP = text_frag_root;  fragP;  fragP = fragP -> fr_next)
  431.     {
  432.       switch (fragP -> fr_type)
  433.     {
  434.     case rs_align:
  435.     case rs_org:
  436.       fragP -> fr_type = rs_fill;
  437.       know( fragP -> fr_var == 1 );
  438.       know( fragP -> fr_next );
  439.       fragP -> fr_offset
  440.         =     fragP -> fr_next -> fr_address
  441.           -   fragP -> fr_address
  442.         - fragP -> fr_fix;
  443.       break;
  444.  
  445.     case rs_fill:
  446.       break;
  447.  
  448.     case rs_machine_dependent:
  449.       md_convert_frag (fragP);
  450.       /*
  451.        * After md_convert_frag, we make the frag into a ".space 0".
  452.        * Md_convert_frag() should set up any fixSs and constants
  453.        * required.
  454.        */
  455.       frag_wane (fragP);
  456.       break;
  457.  
  458. #ifndef WORKING_DOT_WORD
  459.     case rs_broken_word:
  460.       {
  461.         struct broken_word *lie;
  462.         extern md_short_jump_size;
  463.         extern md_long_jump_size;
  464.  
  465.         if(fragP->fr_subtype) {
  466.           fragP->fr_fix+=md_short_jump_size;
  467.           for(lie=(struct broken_word *)(fragP->fr_symbol);lie && lie->dispfrag==fragP;lie=lie->next_broken_word)
  468.         if(lie->added==1)
  469.           fragP->fr_fix+=md_long_jump_size;
  470.         }
  471.         frag_wane(fragP);
  472.       }
  473.       break;
  474. #endif
  475.  
  476.     default:
  477.       BAD_CASE( fragP -> fr_type );
  478.       break;
  479.     }            /* switch (fr_type) */
  480.     }                /* for each frag. */
  481.  
  482. #ifndef WORKING_DOT_WORD
  483.     {
  484.       struct broken_word *lie;
  485.       struct broken_word **prevP;
  486.  
  487.       prevP= &broken_words;
  488.       for(lie=broken_words; lie; lie=lie->next_broken_word)
  489.     if(!lie->added) {
  490. #ifdef SPARC
  491.       fix_new(    lie->frag,  lie->word_goes_here - lie->frag->fr_literal,
  492.               2,  lie->add,
  493.             lie->sub,  lie->addnum,
  494.             0,  NO_RELOC);
  495. #endif
  496. #ifdef NS32K
  497.       fix_new_ns32k(lie->frag,
  498.               lie->word_goes_here - lie->frag->fr_literal,
  499.             2,
  500.             lie->add,
  501.             lie->sub,
  502.             lie->addnum,
  503.             0, 2, 0, 0);
  504. #endif
  505. #if !defined(SPARC) && !defined(NS32K)
  506.       fix_new(    lie->frag,  lie->word_goes_here - lie->frag->fr_literal,
  507.               2,  lie->add,
  508.             lie->sub,  lie->addnum,
  509.             0);
  510. #endif
  511.       /* md_number_to_chars(lie->word_goes_here,
  512.                    lie->add->sy_value
  513.                    + lie->addnum
  514.                    - (lie->sub->sy_value),
  515.                  2); */
  516.       *prevP=lie->next_broken_word;
  517.     } else
  518.       prevP= &(lie->next_broken_word);
  519.  
  520.       for(lie=broken_words;lie;) {
  521.     struct broken_word *untruth;
  522.     char    *table_ptr;
  523.     long    table_addr;
  524.     long    from_addr,
  525.         to_addr;
  526.     int    n,
  527.         m;
  528.  
  529.     extern    md_short_jump_size;
  530.     extern    md_long_jump_size;
  531.     void    md_create_short_jump();
  532.     void    md_create_long_jump();
  533.  
  534.  
  535.  
  536.     fragP=lie->dispfrag;
  537.  
  538.     /* Find out how many broken_words go here */
  539.     n=0;
  540.     for(untruth=lie;untruth && untruth->dispfrag==fragP;untruth=untruth->next_broken_word)
  541.       if(untruth->added==1)
  542.         n++;
  543.  
  544.     table_ptr=lie->dispfrag->fr_opcode;
  545.     table_addr=lie->dispfrag->fr_address+(table_ptr - lie->dispfrag->fr_literal);
  546.     /* Create the jump around the long jumps */
  547.     /* This is a short jump from table_ptr+0 to table_ptr+n*long_jump_size */
  548.     from_addr=table_addr;
  549.     to_addr = table_addr + md_short_jump_size + n * md_long_jump_size;
  550.     md_create_short_jump(table_ptr,from_addr,to_addr,lie->dispfrag,lie->add);
  551.     table_ptr+=md_short_jump_size;
  552.     table_addr+=md_short_jump_size;
  553.  
  554.     for(m=0;lie && lie->dispfrag==fragP;m++,lie=lie->next_broken_word) {
  555.       if(lie->added==2)
  556.         continue;
  557.       /* Patch the jump table */
  558.       /* This is the offset from ??? to table_ptr+0 */
  559.       to_addr =   table_addr
  560.                 - (lie->sub->sy_value);
  561.       md_number_to_chars(lie->word_goes_here,to_addr,2);
  562.       for(untruth=lie->next_broken_word;untruth && untruth->dispfrag==fragP;untruth=untruth->next_broken_word) {
  563.         if(untruth->use_jump==lie)
  564.           md_number_to_chars(untruth->word_goes_here,to_addr,2);
  565.       }
  566.  
  567.       /* Install the long jump */
  568.       /* this is a long jump from table_ptr+0 to the final target */
  569.       from_addr=table_addr;
  570.       to_addr=lie->add->sy_value+lie->addnum;
  571.       md_create_long_jump(table_ptr,from_addr,to_addr,lie->dispfrag,lie->add);
  572.       table_ptr+=md_long_jump_size;
  573.       table_addr+=md_long_jump_size;
  574.     }
  575.       }
  576.     }
  577. #endif
  578. #ifndef    VMS
  579.   /*
  580.    * Scan every FixS performing fixups. We had to wait until now to do
  581.    * this because md_convert_frag() may have made some fixSs.
  582.    */
  583.   /* the_exec . a_trsize
  584.     = sizeof(struct relocation_info) * fixup_segment (text_fix_root, N_TEXT);
  585.   the_exec . a_drsize
  586.     = sizeof(struct relocation_info) * fixup_segment (data_fix_root, N_DATA); */
  587.  
  588.   tr_siz=sizeof(struct relocation_info) * fixup_segment (text_fix_root, N_TEXT);
  589.   md_number_to_chars((char *)&the_exec.a_trsize, tr_siz ,sizeof(the_exec.a_trsize));
  590.   dr_siz=sizeof(struct relocation_info) * fixup_segment (data_fix_root, N_DATA);
  591.   md_number_to_chars((char *)&the_exec.a_drsize, dr_siz, sizeof(the_exec.a_drsize));
  592. #ifdef EXEC_MACHINE_TYPE
  593.   md_number_to_chars((char *)&the_exec.a_machtype, EXEC_MACHINE_TYPE, sizeof(the_exec.a_machtype));
  594. #endif
  595.  
  596. #if 0
  597.   md_number_to_chars((char *)&the_exec.a_magic,omagic,sizeof(the_exec.a_magic));
  598. #else
  599.   /* this is a hack to make this thing work with the new sys/exec.h */
  600.   md_number_to_chars((char *)&the_exec, omagic, sizeof(int));
  601. #endif
  602.   md_number_to_chars((char *)&the_exec.a_entry,0,sizeof(the_exec.a_entry));
  603.   /* the_exec . a_entry = 0; */
  604.  
  605.   size_of_the_object_file =
  606.     sizeof( the_exec ) +
  607.       text_siz +
  608.         data_siz +
  609.       syms_siz +
  610.         tr_siz +
  611.           dr_siz +
  612.         string_byte_count;
  613.     
  614.   next_object_file_charP
  615.     = the_object_file
  616.       = xmalloc ( size_of_the_object_file );
  617.  
  618.   output_file_create (out_file_name);
  619.  
  620.   append (& next_object_file_charP, (char *)(&the_exec), (unsigned long)sizeof(the_exec));
  621.  
  622.   /*
  623.    * Emit code.
  624.    */
  625.   for (fragP = text_frag_root;  fragP;  fragP = fragP -> fr_next)
  626.     {
  627.       register long int        count;
  628.       register char *        fill_literal;
  629.       register long int        fill_size;
  630.  
  631.       know( fragP -> fr_type == rs_fill );
  632.       append (& next_object_file_charP, fragP -> fr_literal, (unsigned long)fragP -> fr_fix);
  633.       fill_literal= fragP -> fr_literal + fragP -> fr_fix;
  634.       fill_size   = fragP -> fr_var;
  635.       know( fragP -> fr_offset >= 0 );
  636.       for (count = fragP -> fr_offset;  count;  count --)
  637.       append (& next_object_file_charP, fill_literal, (unsigned long)fill_size);
  638.     }                /* for each code frag. */
  639.  
  640.   /*
  641.    * Emit relocations.
  642.    */
  643.   emit_relocations (text_fix_root, (relax_addressT)0);
  644.   emit_relocations (data_fix_root, text_last_frag -> fr_address);
  645.   /*
  646.    * Emit all symbols left in the symbol chain.
  647.    * Any symbol still undefined is made N_EXT.
  648.    */
  649.   for (   symbolP = symbol_rootP;   symbolP;   symbolP = symbolP -> sy_next   )
  650.     {
  651.       register char *    temp;
  652.  
  653.       temp = symbolP -> sy_nlist . n_un . n_name;
  654.       /* JF fix the numbers up. Call by value RULES! */
  655.       md_number_to_chars((char *)&(symbolP -> sy_nlist  . n_un . n_strx ),symbolP -> sy_name_offset,sizeof(symbolP -> sy_nlist  . n_un . n_strx ));
  656.       md_number_to_chars((char *)&(symbolP->sy_nlist.n_desc),symbolP->sy_nlist.n_desc,sizeof(symbolP -> sy_nlist  . n_desc));
  657.       md_number_to_chars((char *)&(symbolP->sy_nlist.n_value),symbolP->sy_nlist.n_value,sizeof(symbolP->sy_nlist.n_value));
  658.       /* symbolP -> sy_nlist  . n_un . n_strx = symbolP -> sy_name_offset; JF replaced by md above */
  659.       if (symbolP -> sy_type == N_UNDF)
  660.       symbolP -> sy_type |= N_EXT; /* Any undefined symbols become N_EXT. */
  661.       append (& next_object_file_charP, (char *)(& symbolP -> sy_nlist),
  662.           (unsigned long)sizeof(struct nlist));
  663.       symbolP -> sy_nlist . n_un . n_name = temp;
  664.     }                /* for each symbol */
  665.  
  666.   /*
  667.    * next_object_file_charP -> slot for next object byte.
  668.    * Emit strings.
  669.    * Find strings by crawling along symbol table chain.
  670.    */
  671. /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
  672.   md_number_to_chars((char *)&string_byte_count, string_byte_count, sizeof(string_byte_count));
  673.  
  674.   append (& next_object_file_charP, (char *)&string_byte_count, (unsigned long)sizeof(string_byte_count));
  675.   for (   symbolP = symbol_rootP;   symbolP;   symbolP = symbolP -> sy_next   )
  676.     {
  677.       if (symbolP -> sy_name)
  678.     {            /* Ordinary case: not .stabd. */
  679.       append (& next_object_file_charP, symbolP -> sy_name,
  680.           (unsigned long)(strlen (symbolP -> sy_name) + 1));
  681.     }
  682.     }                /* for each symbol */
  683.  
  684.   know( next_object_file_charP == the_object_file + size_of_the_object_file );
  685.  
  686.   output_file_append (the_object_file, size_of_the_object_file, out_file_name);
  687.  
  688.   if (flagseen['G'])        /* GDB symbol file to be appended? */
  689.     {
  690.       gdb_emit (out_file_name);
  691.       gdb_end ();
  692.     }
  693.  
  694.   output_file_close (out_file_name);
  695. #else    /* VMS */
  696.   /*
  697.    *    Now do the VMS-dependent part of writing the object file
  698.    */
  699.   VMS_write_object_file(text_siz, data_siz, text_frag_root, data_frag_root);
  700. #endif    /* VMS */
  701. }                /* write_object_file() */
  702.  
  703. /*
  704.  *            relax_segment()
  705.  *
  706.  * Now we have a segment, not a crowd of sub-segments, we can make fr_address
  707.  * values.
  708.  *
  709.  * Relax the frags.
  710.  *
  711.  * After this, all frags in this segment have addresses that are correct
  712.  * within the segment. Since segments live in different file addresses,
  713.  * these frag addresses may not be the same as final object-file addresses.
  714.  */
  715. #ifndef    VMS
  716. static
  717. #endif    /* not VMS */
  718. void
  719. relax_segment (segment_frag_root, segment_type)
  720.      struct frag *    segment_frag_root;
  721.      segT        segment_type; /* N_DATA or N_TEXT */
  722. {
  723.   register struct frag *    fragP;
  724.   register relax_addressT    address;
  725.   /* register relax_addressT    old_address; JF unused */
  726.   /* register relax_addressT    new_address; JF unused */
  727.  
  728.   know( segment_type == SEG_DATA || segment_type == SEG_TEXT );
  729.  
  730.   /* In case md_estimate_size_before_relax() wants to make fixSs. */
  731.   subseg_change (segment_type, 0);
  732.  
  733.   /*
  734.    * For each frag in segment: count and store  (a 1st guess of) fr_address.
  735.    */
  736.   address = 0;
  737.   for ( fragP = segment_frag_root;   fragP;   fragP = fragP -> fr_next )
  738.     {
  739.       fragP -> fr_address = address;
  740.       address += fragP -> fr_fix;
  741.       switch (fragP -> fr_type)
  742.     {
  743.     case rs_fill:
  744.       address += fragP -> fr_offset * fragP -> fr_var;
  745.       break;
  746.  
  747.     case rs_align:
  748.       address += relax_align (address, fragP -> fr_offset);
  749.       break;
  750.  
  751.     case rs_org:
  752.       /*
  753.        * Assume .org is nugatory. It will grow with 1st relax.
  754.        */
  755.       break;
  756.  
  757.     case rs_machine_dependent:
  758.       address += md_estimate_size_before_relax
  759.         (fragP, seg_N_TYPE [(int) segment_type]);
  760.       break;
  761.  
  762. #ifndef WORKING_DOT_WORD
  763.         /* Broken words don't concern us yet */
  764.     case rs_broken_word:
  765.         break;
  766. #endif
  767.  
  768.     default:
  769.       BAD_CASE( fragP -> fr_type );
  770.       break;
  771.     }            /* switch(fr_type) */
  772.     }                /* for each frag in the segment */
  773.  
  774.   /*
  775.    * Do relax().
  776.    */
  777.   {
  778.     register long int    stretch; /* May be any size, 0 or negative. */
  779.                 /* Cumulative number of addresses we have */
  780.                 /* relaxed this pass. */
  781.                 /* We may have relaxed more than one address. */
  782.     register long int stretched;  /* Have we stretched on this pass? */
  783.                   /* This is 'cuz stretch may be zero, when,
  784.                      in fact some piece of code grew, and
  785.                      another shrank.  If a branch instruction
  786.                      doesn't fit anymore, we could be scrod */
  787.  
  788.     do
  789.       {
  790.     stretch = stretched = 0;
  791.     for (fragP = segment_frag_root;  fragP;  fragP = fragP -> fr_next)
  792.       {
  793.         register long int    growth;
  794.         register long int    was_address;
  795.         /* register long int    var; */
  796.         register long int    offset;
  797.         register symbolS *    symbolP;
  798.         register long int    target;
  799.         register long int    after;
  800.         register long int    aim;
  801.  
  802.         was_address = fragP -> fr_address;
  803.         address = fragP -> fr_address += stretch;
  804.         symbolP = fragP -> fr_symbol;
  805.         offset = fragP -> fr_offset;
  806.         /* var = fragP -> fr_var; */
  807.         switch (fragP -> fr_type)
  808.           {
  809.           case rs_fill:    /* .fill never relaxes. */
  810.         growth = 0;
  811.         break;
  812.  
  813. #ifndef WORKING_DOT_WORD
  814.         /* JF:  This is RMS's idea.  I do *NOT* want to be blamed
  815.            for it I do not want to write it.  I do not want to have
  816.            anything to do with it.  This is not the proper way to
  817.            implement this misfeature. */
  818.           case rs_broken_word:
  819.             {
  820.         struct broken_word *lie;
  821.         struct broken_word *untruth;
  822.         extern int md_short_jump_size;
  823.         extern int md_long_jump_size;
  824.  
  825.             /* Yes this is ugly (storing the broken_word pointer
  826.                in the symbol slot).  Still, this whole chunk of
  827.                code is ugly, and I don't feel like doing anything
  828.                about it.  Think of it as stubbornness in action */
  829.         growth=0;
  830.             for(lie=(struct broken_word *)(fragP->fr_symbol);
  831.             lie && lie->dispfrag==fragP;
  832.             lie=lie->next_broken_word) {
  833.  
  834.             if(lie->added)
  835.                 continue;
  836.             offset=  lie->add->sy_frag->fr_address+lie->add->sy_value + lie->addnum -
  837.                 (lie->sub->sy_frag->fr_address+lie->sub->sy_value);
  838.             if(offset<=-32768 || offset>=32767) {
  839.                 if(flagseen['k'])
  840.                     as_warn(".word %s-%s+%ld didn't fit",lie->add->sy_name,lie->sub->sy_name,lie->addnum);
  841.                 lie->added=1;
  842.                 if(fragP->fr_subtype==0) {
  843.                     fragP->fr_subtype++;
  844.                     growth+=md_short_jump_size;
  845.                 }
  846.                 for(untruth=lie->next_broken_word;untruth && untruth->dispfrag==lie->dispfrag;untruth=untruth->next_broken_word)
  847.                     if(untruth->add->sy_frag==lie->add->sy_frag && untruth->add->sy_value==lie->add->sy_value) {
  848.                         untruth->added=2;
  849.                         untruth->use_jump=lie;
  850.                     }
  851.                 growth+=md_long_jump_size;
  852.             }
  853.             }
  854.         }
  855.         break;
  856. #endif
  857.           case rs_align:
  858.         growth = relax_align ((relax_addressT)(address + fragP -> fr_fix), offset)
  859.           - relax_align ((relax_addressT)(was_address +  fragP -> fr_fix), offset);
  860.         break;
  861.  
  862.           case rs_org:
  863.         target = offset;
  864.         if (symbolP)
  865.           {
  866.             know(   ((symbolP -> sy_type & N_TYPE) == N_ABS) || ((symbolP -> sy_type & N_TYPE) == N_DATA) || ((symbolP -> sy_type & N_TYPE) == N_TEXT));
  867.             know( symbolP -> sy_frag );
  868.             know( (symbolP->sy_type&N_TYPE)!=N_ABS || symbolP->sy_frag==&zero_address_frag );
  869.             target +=
  870.               symbolP -> sy_value
  871.             + symbolP -> sy_frag -> fr_address;
  872.           }
  873.         know( fragP -> fr_next );
  874.         after = fragP -> fr_next -> fr_address;
  875.         growth - ((target - after ) > 0) ? (target - after) : 0;
  876.                 /* Growth may be -ve, but variable part */
  877.                 /* of frag cannot have < 0 chars. */
  878.                 /* That is, we can't .org backwards. */
  879.  
  880.         growth -= stretch;    /* This is an absolute growth factor */
  881.         break;
  882.  
  883.           case rs_machine_dependent:
  884.         {
  885.           register relax_typeS *    this_type;
  886.           register relax_typeS *    start_type;
  887.           register relax_substateT    next_state;
  888.           register relax_substateT    this_state;
  889.  
  890.           start_type = this_type
  891.             = md_relax_table + (this_state = fragP -> fr_subtype);
  892.         target = offset;
  893.         if (symbolP)
  894.           {
  895.  know(   ((symbolP -> sy_type & N_TYPE) == N_ABS) || ((symbolP -> sy_type &
  896.  N_TYPE) == N_DATA) || ((symbolP -> sy_type & N_TYPE) == N_TEXT));
  897.             know( symbolP -> sy_frag );
  898.             know( (symbolP->sy_type&N_TYPE)!=N_ABS || symbolP->sy_frag==&zero_address_frag );
  899.             target +=
  900.               symbolP -> sy_value
  901.             + symbolP -> sy_frag -> fr_address;
  902.  
  903.             /* If frag has yet to be reached on this pass,
  904.                assume it will move by STRETCH just as we did.
  905.                If this is not so, it will be because some frag
  906.                between grows, and that will force another pass.  */
  907.  
  908.                    /* JF was just address */
  909.                 /* JF also added isdnrange hack */
  910.                 /* There's gotta be a better/faster/etc way
  911.                    to do this. . . */
  912.             if (symbolP->sy_frag->fr_address > was_address && isdnrange(fragP,symbolP->sy_frag))
  913.               target += stretch;
  914.  
  915.           }
  916.           aim = target - address - fragP -> fr_fix;
  917.           if (aim < 0)
  918.             {
  919.               /* Look backwards. */
  920.               for (next_state = this_type -> rlx_more;  next_state;  )
  921.             {
  922.               if (aim >= this_type -> rlx_backward)
  923.                   next_state = 0;
  924.               else
  925.                 {    /* Grow to next state. */
  926.                   this_type = md_relax_table + (this_state = next_state);
  927.                   next_state = this_type -> rlx_more;
  928.                 }
  929.             }
  930.             }
  931.           else
  932.             {
  933. #ifdef DONTDEF
  934. /* JF these next few lines of code are for the mc68020 which can't handle short
  935.    offsets of zero in branch instructions.  What a kludge! */
  936.  if(aim==0 && this_state==(1<<2+0)) {    /* FOO hard encoded from m.c */
  937.     aim=this_type->rlx_forward+1;    /* Force relaxation into word mode */
  938.  }
  939. #endif
  940. /* JF end of 68020 code */
  941.               /* Look forwards. */
  942.               for (next_state = this_type -> rlx_more;  next_state;  )
  943.             {
  944.               if (aim <= this_type -> rlx_forward)
  945.                   next_state = 0;
  946.               else
  947.                 {    /* Grow to next state. */
  948.                   this_type = md_relax_table + (this_state = next_state);
  949.                   next_state = this_type -> rlx_more;
  950.                 }
  951.             }
  952.             }
  953.           if (growth = this_type -> rlx_length - start_type -> rlx_length)
  954.               fragP -> fr_subtype = this_state;
  955.         }
  956.         break;
  957.  
  958.           default:
  959.         BAD_CASE( fragP -> fr_type );
  960.         break;
  961.           }
  962.         if(growth) {
  963.           stretch += growth;
  964.           stretched++;
  965.         }
  966.       }            /* For each frag in the segment. */
  967.       } while (stretched);    /* Until nothing further to relax. */
  968.   }
  969.  
  970.   /*
  971.    * We now have valid fr_address'es for each frag.
  972.    */
  973.  
  974.   /*
  975.    * All fr_address's are correct, relative to their own segment.
  976.    * We have made all the fixS we will ever make.
  977.    */
  978. }                /* relax_segment() */
  979.  
  980. /*
  981.  * Relax_align. Advance location counter to next address that has 'alignment'
  982.  * lowest order bits all 0s.
  983.  */
  984.  
  985. static relax_addressT        /* How many addresses does the .align take? */
  986. relax_align (address, alignment)
  987.      register relax_addressT    address; /* Address now. */
  988.      register long int        alignment; /* Alignment (binary). */
  989. {
  990.   relax_addressT    mask;
  991.   relax_addressT    new_address;
  992.  
  993.   mask = ~ ( (~0) << alignment );
  994.   new_address = (address + mask) & (~ mask);
  995.   return (new_address - address);
  996. }
  997.  
  998. /*
  999.  *            fixup_segment()
  1000.  */
  1001. static long int
  1002. fixup_segment (fixP, this_segment_type)
  1003.      register fixS *    fixP;
  1004.      int        this_segment_type; /* N_TYPE bits for segment. */
  1005. {
  1006.   register long int        seg_reloc_count;
  1007.         /* JF these all used to be local to the for loop, but GDB doesn't seem to be able to deal with them there, so I moved them here for a bit. */
  1008.       register symbolS *    add_symbolP;
  1009.       register symbolS *    sub_symbolP;
  1010.       register long int        add_number;
  1011.       register int        size;
  1012.       register char *        place;
  1013.       register long int        where;
  1014.       register char        pcrel;
  1015.       register fragS *        fragP;
  1016.       register int        add_symbol_N_TYPE;
  1017.  
  1018.  
  1019.   seg_reloc_count = 0;
  1020.   for ( ;  fixP;  fixP = fixP -> fx_next)
  1021.     {
  1022.       fragP       = fixP  -> fx_frag;
  1023.       know( fragP );
  1024.       where      = fixP  -> fx_where;
  1025.       place       = fragP -> fr_literal + where;
  1026.       size      = fixP  -> fx_size;
  1027.       add_symbolP = fixP  -> fx_addsy;
  1028.       sub_symbolP = fixP  -> fx_subsy;
  1029.       add_number  = fixP  -> fx_offset;
  1030.       pcrel      = fixP  -> fx_pcrel;
  1031.       if(add_symbolP)
  1032.     add_symbol_N_TYPE = add_symbolP -> sy_type & N_TYPE;
  1033.       if (sub_symbolP)
  1034.     {
  1035.       if(!add_symbolP)    /* Its just -sym */
  1036.         {
  1037.           if(sub_symbolP->sy_type!=N_ABS)
  1038.             as_warn("Negative of non-absolute symbol %s", sub_symbolP->sy_name);
  1039.           add_number-=sub_symbolP->sy_value;
  1040.         }
  1041.       else if (   ((sub_symbolP -> sy_type ^ add_symbol_N_TYPE) & N_TYPE) == 0
  1042.           && (   add_symbol_N_TYPE == N_DATA
  1043.           || add_symbol_N_TYPE == N_TEXT
  1044.           || add_symbol_N_TYPE == N_BSS
  1045.           || add_symbol_N_TYPE == N_ABS))
  1046.         {
  1047.           /* Difference of 2 symbols from same segment. */
  1048.           /* Can't make difference of 2 undefineds: 'value' means */
  1049.           /* something different for N_UNDF. */
  1050.           add_number += add_symbolP -> sy_value - sub_symbolP -> sy_value;
  1051.           add_symbolP = NULL;
  1052.           fixP -> fx_addsy = NULL;
  1053.         }
  1054.       else
  1055.         {
  1056.           /* Different segments in subtraction. */
  1057.           know( sub_symbolP -> sy_type != (N_ABS | N_EXT))
  1058.         if (sub_symbolP -> sy_type == N_ABS)
  1059.             add_number -= sub_symbolP -> sy_value;
  1060.         else
  1061.           {
  1062.                as_warn("Can't emit reloc {- %s-seg symbol \"%s\"} @@ file address %d.",
  1063.                     seg_name[(int)N_TYPE_seg[sub_symbolP->sy_type&N_TYPE]],
  1064.                     sub_symbolP -> sy_name, fragP -> fr_address + where);
  1065.           }
  1066.         }
  1067.     }
  1068.       if (add_symbolP)
  1069.     {
  1070.       if (add_symbol_N_TYPE == this_segment_type && pcrel)
  1071.         {
  1072.           /*
  1073.            * This fixup was made when the symbol's segment was
  1074.            * SEG_UNKNOWN, but it is now in the local segment.
  1075.            * So we know how to do the address without relocation.
  1076.            */
  1077.           add_number += add_symbolP -> sy_value;
  1078.           add_number -= size + where + fragP -> fr_address;
  1079.           pcrel = 0;    /* Lie. Don't want further pcrel processing. */
  1080.           fixP -> fx_addsy = NULL; /* No relocations please. */
  1081.           /*
  1082.            * It would be nice to check that the address does not overflow.
  1083.            * I didn't do this check because:
  1084.            * +  It is machine dependent in the general case (eg 32032)
  1085.            * +  Compiler output will never need this checking, so why
  1086.            *    slow down the usual case?
  1087.            */
  1088.         }
  1089.       else
  1090.         {
  1091.           switch (add_symbol_N_TYPE)
  1092.         {
  1093.         case N_ABS:
  1094.           add_number += add_symbolP -> sy_value;
  1095.           fixP -> fx_addsy = NULL;
  1096.           add_symbolP = NULL;
  1097.           break;
  1098.           
  1099.         case N_BSS:
  1100.         case N_DATA:
  1101.         case N_TEXT:
  1102.           seg_reloc_count ++;
  1103.           add_number += add_symbolP -> sy_value;
  1104.           break;
  1105.           
  1106.         case N_UNDF:
  1107.           seg_reloc_count ++;
  1108.           break;
  1109.           
  1110.         default:
  1111.           BAD_CASE( add_symbol_N_TYPE );
  1112.           break;
  1113.         }        /* switch on symbol seg */
  1114.         }            /* if not in local seg */
  1115.     }            /* if there was a + symbol */
  1116.       if (pcrel)
  1117.     {
  1118.       add_number -= size + where + fragP -> fr_address;
  1119.       if (add_symbolP == 0)
  1120.         {
  1121.           fixP -> fx_addsy = & abs_symbol;
  1122.           seg_reloc_count ++;
  1123.         }
  1124.     }
  1125.       /* OVE added fx_im_disp for ns32k and others */
  1126.       if (!fixP->fx_bit_fixP) {
  1127.     /* JF I hope this works . . . */
  1128.     if((size==1 && (add_number& ~0xFF)   && (add_number&~0xFF!=(-1&~0xFF))) ||
  1129.        (size==2 && (add_number& ~0xFFFF) && (add_number&~0xFFFF!=(-1&~0xFFFF))))
  1130.       as_warn("Fixup of %d too large for field width of %d",add_number, size);
  1131.  
  1132.     switch (fixP->fx_im_disp) {
  1133.     case 0:
  1134. #ifdef SPARC
  1135.       fixP->fx_addnumber = add_number;
  1136.       md_number_to_imm(place, add_number, size, fixP, this_segment_type);
  1137. #else
  1138.       md_number_to_imm (place, add_number, size);
  1139.       /* OVE: the immediates, like disps, have lsb at lowest address */
  1140. #endif
  1141.       break;
  1142.     case 1:
  1143.       md_number_to_disp (place,
  1144.                  fixP->fx_pcrel ? add_number+fixP->fx_pcrel_adjust:add_number,
  1145.                  size);
  1146.       break;
  1147.     case 2: /* fix requested for .long .word etc */
  1148.       md_number_to_chars (place, add_number, size);
  1149.       break;
  1150.     default:
  1151.       as_fatal("Internal error in write.c in fixup_segment");
  1152.     } /* OVE: maybe one ought to put _imm _disp _chars in one md-func */
  1153.       } else {
  1154.     md_number_to_field (place, add_number, fixP->fx_bit_fixP);
  1155.       }
  1156.     }                /* For each fixS in this segment. */
  1157.   return (seg_reloc_count);
  1158. }                /* fixup_segment() */
  1159.  
  1160.  
  1161. /* The sparc needs its own emit_relocations() */
  1162. #ifndef SPARC
  1163. /*
  1164.  *        emit_relocations()
  1165.  *
  1166.  * Crawl along a fixS chain. Emit the segment's relocations.
  1167.  */
  1168. static void
  1169. emit_relocations (fixP, segment_address_in_file)
  1170.      register fixS *    fixP;    /* Fixup chain for this segment. */
  1171.      relax_addressT    segment_address_in_file;
  1172. {
  1173.   struct relocation_info    ri;
  1174.   register symbolS *        symbolP;
  1175.  
  1176.     /* JF this is for paranoia */
  1177.   bzero((char *)&ri,sizeof(ri));
  1178.   for ( ;  fixP;  fixP = fixP -> fx_next)
  1179.     {
  1180.       if (symbolP = fixP -> fx_addsy)
  1181.     {
  1182.  
  1183. #ifndef hpux
  1184.         /* These two 'cuz of NS32K */
  1185.       ri . r_bsr        = fixP -> fx_bsr;
  1186.       ri . r_disp        = fixP -> fx_im_disp;
  1187. #endif
  1188.  
  1189.       ri . r_length        = nbytes_r_length [fixP -> fx_size];
  1190.       ri . r_pcrel        = fixP -> fx_pcrel;
  1191.       ri . r_address    = fixP -> fx_frag -> fr_address
  1192.         +   fixP -> fx_where
  1193.           - segment_address_in_file;
  1194.       if ((symbolP -> sy_type & N_TYPE) == N_UNDF)
  1195.         {
  1196.           ri . r_extern    = 1;
  1197.           ri . r_symbolnum    = symbolP -> sy_number;
  1198.         }
  1199.       else
  1200.         {
  1201.           ri . r_extern    = 0;
  1202.           ri . r_symbolnum    = symbolP -> sy_type & N_TYPE;
  1203.         }
  1204.  
  1205.       /* 
  1206.         The 68k machines assign bit-fields from higher bits to 
  1207.         lower bits ("left-to-right") within the int.  VAXen assign 
  1208.         bit-fields from lower bits to higher bits ("right-to-left").
  1209.         Both handle multi-byte numbers in their usual fashion
  1210.         (Big-endian and little-endian stuff).
  1211.         Thus we need a machine dependent routine to make
  1212.         sure the structure is written out correctly.  FUN!
  1213.        */
  1214.       md_ri_to_chars((char *) &ri, ri); 
  1215.       append (&next_object_file_charP, (char *)& ri, (unsigned long)sizeof(ri));
  1216.     }
  1217.     }
  1218.  
  1219. }
  1220. #endif
  1221.  
  1222. int
  1223. isdnrange(f1,f2)
  1224. struct frag *f1,*f2;
  1225. {
  1226.     while(f1) {
  1227.         if(f1->fr_next==f2)
  1228.             return 1;
  1229.         f1=f1->fr_next;
  1230.     }
  1231.     return 0;
  1232. }
  1233. /* End: as-write.c */
  1234. @
  1235.  
  1236.  
  1237. 1.1
  1238. log
  1239. @Initial revision
  1240. @
  1241. text
  1242. @d567 1
  1243. d569 4
  1244. @
  1245.